package cn.codingjc.framework.common.core.status.model;

import lombok.Data;

/**
 * @ClassName PayModel
 * @Description 支付状态模型
 * @Author jccoding
 * @Date 2024/3/5 17:26
 * @Version 1.0
 **/

@Data
public class PayModel {

    /**
     * 上次状态
     */
    private PaymentStatus lastStatus;

    /**
     * 当前状态
     */
    private PaymentStatus currentStatus;

    public PayModel(PaymentStatus lastStatus, PaymentStatus currentStatus) {
        this.lastStatus = lastStatus;
        this.currentStatus = currentStatus;
    }

    public void transferStatusByEvent(PaymentEvent event){
        PaymentStatus targetStatus = PaymentStatus.getTargetStatus(currentStatus, event);
        if (targetStatus != null) {
            lastStatus = currentStatus;
            currentStatus = targetStatus;
        } else {
            throw new RuntimeException("illegal status!");
        }
    }

    public static void main(String[] args) {
        PayModel payModel = new PayModel(PaymentStatus.EMPTY, PaymentStatus.EMPTY);
        payModel.transferStatusByEvent(PaymentEvent.PAY_CREATE);
        System.out.println(payModel.getLastStatus());
        System.out.println(payModel.getCurrentStatus());
    }
}
